
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RMISecurityManager;
import java.rmi.server.RMIClassLoader;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ntthinh
 */
public class DictServer {

    public DictServer(String name) {
       // String name = "DictService";
        Dictionnary dictServer = null;
        //A partir de jdk 1.2 (java2), il n'est normalement plus possible de charger quoi que ce soit, si ce n'est du CLASSPATH, sans un fichier explicitant la politique de sécurité ("policy file").
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }
        try {

            dictServer = new DictionnaryImpl();

        } catch (Exception e) {
            System.out.println("Cannot create Dictionnary: " + e);
            //e.printStackTrace();
        }
        while (true) {
            try {
                Registry registry = LocateRegistry.getRegistry();
                registry.rebind(name, dictServer);
            System.out.println(name);
              } catch (Exception e) {
                System.out.println("Unable to start the server " + e.getMessage());
            }

            try {
                Thread.sleep(60000); //10 min.
            } catch (InterruptedException e) {
            }
        }
    }

    public static void main(String[] args) {
        new DictServer(args[0]);
    }
}
